package com.example.system.controller.question;

import com.example.common.core.Controller.BaseController;
import com.example.common.core.domin.R;
import com.example.common.core.domin.TableDataInfo;
import com.example.system.domin.question.Question;
import com.example.system.domin.question.dto.QuestionAddDTO;
import com.example.system.domin.question.dto.QuestionEditDTO;
import com.example.system.domin.question.dto.QuestionQueryDTO;
import com.example.system.domin.question.vo.QuestionDetailVO;
import com.example.system.domin.question.vo.QuestionVO;
import com.example.system.service.question.IQuestionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/question")
@Tag(name = "题目管理接口")
public class QuestionController extends BaseController {

    @Autowired
    private IQuestionService questionService;

    //接口地址: /system/question/list
    @GetMapping("/list")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {
        List<QuestionVO> questionVOList  = questionService.list(questionQueryDTO);
        return getTableDataInfo(questionVOList);
    }

    //接口地址: /system/question/add
    @PostMapping("/add")
    public R<Void> add(@RequestBody QuestionAddDTO questionAddDTO) {
        return toR(questionService.add(questionAddDTO));
    }

    //接口地址: /system/question/detail  -- 题目详情
    @GetMapping("/detail")
    public R<QuestionDetailVO> detail(Long questionId) {
        return R.ok(questionService.detail(questionId));
    }


    //接口地址: /system/question/edit  -- 题目编辑
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody QuestionEditDTO questionEditDTO) {
        return toR(questionService.edit(questionEditDTO));
    }

    //接口地址: /system/question/delete  -- 题目删除
    @DeleteMapping("/delete")
    public R<Void> delete(Long questionId) {
        return toR(questionService.delete(questionId));
    }
}
